package com.company.Demo;

public class LinkedList {
    public Node head;//指向表头地址的引用
    public int length;
    public LinkedList(){//建立头结点
        length=0;
        head=new Node();
        head.data=0;
        head.left=null;
        head.right=null;
    }
    //添加
    public void insert(int x,Node node){
        if(node==null){
            node = new Node(x);
            return;
        }
        //最左边
        if(x<node.data){
            node.left = new Node(x);
            node = node.left;
            return;
        }
        Node temp = node.right;
        while(x>temp.data&&temp!=null){
            node = node.right;
            temp = temp.right;
        }
        Node node1 = new Node(x);
        if(temp!=null){
            //节点在中键
            node1.right = temp;
            node1.left = node;
            node.right = node1;
            temp.left = node1;
        }else{
            //节点在最右边
            node.right = node1;
            node1.left = node;
        }
    }
    public void delete(int x,Node node){

    }
}
